package com.apes.scm.masterdata.product.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.product.model.Category;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface CategoryRepository extends CustomRepository<Category, String> {

    List<Category> findAllByUpdateDateGreaterThanOrderByIdAsc(Date updateDate, Pageable pageable);

    @Query(value = "select A.NAME partsName,B.NAME partsAlias from mas_category A,mas_category_tag B where A.ID = B.category_id and (A.name like %:value% or B.name like %:value%) GROUP BY A.NAME,B.NAME",nativeQuery = true)
    List<Map> findAllByClassify_NameOrName(@Param("value") String value);

    @Query(value = "select A.NAME partsName,B.NAME partsAlias from mas_category A,mas_category_tag B WHERE A.ID = B.category_id AND (A.name = :value or B.name = :value) ",nativeQuery = true)
    List<Map> findByNames(@Param("value") String value);

    Category findByName(String name);
    @Query(value = "select a.id as id from Category a")
    List<String> findAllId();
}
